#ifndef MACROFILEWRITER
#define MACROFILEWRITER

#include <fstream>
#include <vector>
#include <string>

#include "WinMacroLib.h"

class CMacroFileWriter
{
public:
	DWORD WriteMacroFile(LPCTSTR fileName, EVENTMSG* messages, DWORD message_count)
	{
		return WriteToFile(fileName, messages, message_count);	
	}
	
	DWORD WriteMacroFile(LPCTSTR fileName, const std::vector<EVENTMSG> &recorded_messages)
	{
		return WriteToFile(fileName, recorded_messages.begin(), recorded_messages.size());
	}

private:
	template <typename T>
	DWORD WriteToFile(LPCTSTR file_name, T iter, DWORD message_count)
	{
		std::ofstream output;
		output.open(file_name, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
		output.write(signature, signature_length);

		DWORD index = 0;
		while (index < message_count)
		{
			EVENTMSG msg = *iter;
			output.write((const char*)&msg, sizeof(EVENTMSG));
			iter++;
			index++;
		}

		output.close();
		return 0;
	}
};

#endif